/*
 * GravarContatoAction.java
 *
 * Created on 18 de Novembro de 2006, 12:38
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package action;

import controller.Action;
import java.io.IOException;
import javax.servlet.http.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.TipoExercicio;
import percistence.TipoExercicioDAO;
import templateMethod.TipoExercicioGrupoMuscular;

public class GravarTipoExercicioAction implements Action {
    
    public GravarTipoExercicioAction() {
    }
    
    public void execute(HttpServletRequest request,
            HttpServletResponse response ) throws IOException {
        String nome = request.getParameter("textNome");
        String grupoMuscular = request.getParameter("textGrupoMuscular");
        
        TipoExercicio tipoExercicio = new TipoExercicioGrupoMuscular();
        tipoExercicio.setNome(nome);
        tipoExercicio.setGrupoMuscular(grupoMuscular);
        
        if("".equals(tipoExercicio.getNome())) {
            response.sendRedirect("index.jsp");
        } else {
            try {
                TipoExercicioDAO.getInstance().salvar(tipoExercicio);
                response.sendRedirect("index.jsp");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(GravarTipoExercicioAction.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
